<template>
    <a-card :bordered="false">
        <a-button-group style="margin-right: 8px;float: right">
            <a-button type="danger" @click="handleDelete">删除</a-button>
            <a-button type="primary" @click="handleEdit" style="margin-right: 8px;float: right" ><router-link :to="`/template/update/${this.detail.id}`">编辑</router-link></a-button>
        </a-button-group>

        <detail-list title="模板信息详细" :col="3">
            <detail-list-item term="ID">{{detail.id}}</detail-list-item>
            <detail-list-item term="模板名">{{detail.name}}</detail-list-item>
            <detail-list-item term="模板描述">{{detail.info}}</detail-list-item>
            <detail-list-item term="模板地址">{{detail.url}}</detail-list-item>
            <detail-list-item term="创建时间">{{detail.createTime}}</detail-list-item>
            <detail-list-item term="更新时间">{{detail.updateTime}}</detail-list-item>
        </detail-list>





    </a-card>
</template>

<script>
    import DetailList from '@/components/tool/DetailList';
    import {
        templateService,
    } from "@/services";

    import {
    } from "@/columns";


    const DetailListItem = DetailList.Item


    export default {
        name: 'TemplateDetail',
        components: {
            DetailListItem,
            DetailList,
        },
        data () {
            return {
                detail: {
                    id:'',
                    name:'',
                    info:'',
                    url:'',
                    createTime:'',
                    updateTime:'',
                },



            }
        },
        async created() {
            await this.refresh();
        },
        /*页面显示*/
        activated() {
            this.refresh();
        },
        methods:{
            /*刷新方法*/
            async refresh() {
                this.detail.id = this.$route.params.id;
                await this.loadData();
            },

            /*主数据*/
            async loadData() {
                const result = await templateService.getById({id:this.detail.id});
                if (result.code == 200) {
                    this.detail = result.data;
                }
            },
            handleDelete() {
                this.$confirm({
                    title: '删除' + this.detail.id,
                    content:'确定删除id为' + this.detail.id + "的这一项吗",
                    onOk:async () => {
                        const result =  await templateService.remove(this.detail.id);
                        if (result.code == 204) {
                            this.$message.success('删除成功');
                            this.$router.go(-1);
                        } else {
                            this.$message.error('删除失败:' + result.msg);
                        }
                    }
                })
            },
            handleEdit() {

            },





        }
    }
</script>

<style lang="less" scoped>
    .title {
        color: @title-color;
        font-size: 16px;
        font-weight: bolder;
        margin-bottom: 16px;
    }
</style>
